/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.isip.transformation;

/**
 *
 * @author Ahmad Fauzan
 */
public class NineNTransformation implements Transformation{

    @Override
    public int[][] doTransform(int[][] matrix) {
        int[][] new_matrix = new int[matrix.length][matrix[0].length];
        
        for(int i =0; i < matrix.length; i++ ) {
            for(int j=0; j < matrix[i].length; j++) {
                int n = matrix[i][j];
                
                if(i > 0 && j > 0) {
                     if(n < matrix[i-1][j-1]) {
                        n = matrix[i-1][j-1];
                    }
                }
                
                if(i > 0) {
                    if(n < matrix[i-1][j]) {
                        n = matrix[i-1][j];
                    }
                }
                
                if(i > 0 && j < matrix[i].length-1) {
                    if(n < matrix[i-1][j+1]) {
                        n = matrix[i-1][j+1];
                    }
                }
                
                 if(j < matrix[i].length-1) {
                    if(n < matrix[i][j+1]) {
                        n = matrix[i][j+1];
                    }
                }
                 
                
                if(i < matrix.length-1 && j < matrix[i].length-1) {
                    if(n < matrix[i+1][j + 1]) {
                        n = matrix[i+1][j + 1];
                    }
                }
                
                if(i < matrix.length-1) {
                    if(n < matrix[i+1][j]) {
                        n = matrix[i+1][j];
                    }
                }
                
                if(i < matrix.length-1 && j > 0) {
                    if(n < matrix[i+1][j-1]) {
                        n = matrix[i+1][j-1];
                    }
                }
                
                if(j > 0) {
                    if(n < matrix[i][j-1]) {
                        n = matrix[i][j-1];
                    }
                }
                
                new_matrix[i][j] = n;
                
            }
        }
        
        return new_matrix;
    }
    
}
